<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学期" prop="semId">
         <el-select v-model="queryParams.semId" filterable clearable placeholder="请选择学期">
           <el-option
             v-for="item in semsterList"
             :key="item.id"
             :label="item.title"
             :value="item.id"
             size="small">
           </el-option>
         </el-select>
       </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="info" icon="el-icon-download" size="mini" @click="handleExport" >导出</el-button>
      </el-form-item>
    </el-form>
    <div class="chart-wrapper">
      <table-chart v-if="chart.dsId" :chartData="chart" :params="query" :pager="true"/>
    </div>
  </div>
</template>

<script>
import TableChart from '@/components/Charts/TableChart.vue'
import { getChartByCode} from "@/api/sys/chart";
import { selectSemster} from "@/api/base/semster";
import { exportDataset} from "@/api/sys/dataset";

export default {
  name: "ClassScore",
  components: {TableChart},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 选中数组
      chartCode: 'class_score',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 查询参数
      queryParams: {
        semId: null
      },
      query: {},
      // 学期数据
      semsterList: [],
      // 表单参数
      chart: {}
    };
  },
  created() {
    getChartByCode(this.chartCode).then(response => {
      if(!response.data){
        this.msgError("报表不存在");
      }else{
        this.chart = response.data;
      }
    });
    selectSemster({'status':1}).then(response => {
      this.semsterList = response.rows;
    });
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.query = this.queryParams;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.where = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleExport() {
      var ps = this.queryParams;
      ps.chartId = this.chart.id;
      exportDataset({id:this.chart.dsId, params:ps}).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
